/*
 * Copyright (c) 2010. Dylan Schell.
 */

package nl.xs4all.dylanschell.deckprinter.services;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.multibindings.Multibinder;
import nl.xs4all.dylanschell.deckprinter.parser.GenericDeckParser;
import nl.xs4all.dylanschell.deckprinter.parser.MTGODeckParser;
import nl.xs4all.dylanschell.deckprinter.parser.MWDeckParser;
import nl.xs4all.dylanschell.deckprinter.parser.OCTGNDeckParser;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.stream.XMLInputFactory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DeckPrinterModule extends AbstractModule
{
    @Override
    protected void configure()
    {
        bind(DeckPrinterConfig.class)
                .to(DeckPrinterConfigImpl.class);
        bind(DeckPrinter.class)
                .to(PDFDeckPrinter.class);
        bind(ImageService.class)
                .to(ImageServiceImpl.class);
        bind(SetLoader.class).to(OCTGNLoader.class);
        bind(SetService.class)
                .to(SetServiceImpl.class);
        bind(DeckService.class)
                .to(DeckServiceImpl.class);
        bind(DeckParser.class)
                .to(GenericDeckParser.class);
        Multibinder<DeckParser> deckParserBinder = Multibinder.newSetBinder(binder(), DeckParser.class);
        deckParserBinder.addBinding().to(OCTGNDeckParser.class);
        deckParserBinder.addBinding().to(MWDeckParser.class);
        deckParserBinder.addBinding().to(MTGODeckParser.class);
    }

    @Provides
    @Singleton
    public JAXBContext createContext() throws JAXBException
    {
        return JAXBContext.newInstance(
                "org.octgn.cardset:org.octgn.deck:org.octgn.types:org.openxmlformats.schemas._package._2006.relationships");
    }

    @Provides
    @Singleton
    public XMLInputFactory createInputFactory()
    {
        return XMLInputFactory.newFactory();
    }

    @Provides
    @Singleton
    public ExecutorService createExecutorService()
    {
        return Executors.newCachedThreadPool();
    }
}
